package com.lc.railway.ui.activity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.railway.R;
import com.lc.railway.http.request.UpgradeAddApi;
import com.lc.railway.http.response.RegisterBean;
import com.lc.railway.manager.InputTextManager;
import com.lc.widget.view.RegexEditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PowerActivity extends WaterActivity {
    @BindView(R.id.et_register_name)
    EditText etRegisterName;
    @BindView(R.id.et_register_work)
    EditText etRegisterWork;
    @BindView(R.id.et_register_job)
    EditText etRegisterJob;
    @BindView(R.id.et_register_alarm)
    EditText etRegisterAlarm;
    @BindView(R.id.et_register_password)
    RegexEditText etRegisterPassword;
    @BindView(R.id.et_power)
    EditText etPower;
    @BindView(R.id.btn_register)
    Button btnRegister;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_power;

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        InputTextManager.with(this)
                .addView(etRegisterName)
                .addView(etRegisterWork)
                .addView(etRegisterJob)
                .addView(etRegisterAlarm)
                .addView(etRegisterPassword)
                .addView(etPower)
                .setMain(btnRegister)
                .build();

    }

    private void upgrade_add() {
        EasyHttp.post(this)
                .api(new UpgradeAddApi().setName(etRegisterName.getText().toString().trim()).setNumber(etRegisterAlarm.getText().toString().trim()).setJob(etRegisterJob.getText().toString().trim()).setUnit(etRegisterWork.getText().toString().trim()).setContent(etPower.getText().toString()))
                .request(new HttpCallback<RegisterBean>(this) {
                    @Override
                    public void onSucceed(RegisterBean data) {

                        if (data.getError_code() == 200) {

                        finish();
                        }
                    }
                });
    }

    @OnClick(R.id.btn_register)
    public void onClick() {
        upgrade_add();
    }
}
